package tr.richfacesext.resourcemanagement;

import java.io.Serializable;
import java.util.List;

/**
 * 
 * @author mert
 *
 */
@SuppressWarnings("serial")
public class ResourceManager implements Serializable {
	
	private static ThreadLocal resources = new ThreadLocal();

	public static void addResource(String resourceName) {
		if(resources.get() == null)
			initResources();
			
		((ResourceHolder)resources.get()).addResource(resourceName);
	}
	
	public static List getResources() {
		if(resources.get() == null)
			initResources();
		
		return ((ResourceHolder)resources.get()).getResources();
	}
	
	public static void clearResources() {
		if(resources.get() != null) {
			((ResourceHolder)resources.get()).emptyResources();
			resources.set(null);
		}
	}
	
	private static void initResources() {
		resources.set(new ResourceHolder());
	}	
}